﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using F_MODEL;
using F_BLL;
using MvcApplication1.Models;
using System.Web;


namespace MvcApplication1.Controllers
{
    public class UserInfoController : zyl_LoginController
    {
        UserInfoBll userBll = new UserInfoBll();

        //<summary>

        //</summary>
        //<param name="flyman"></param>
        //<returns></returns>
        [HttpPost]
        public int BeFlyMan(Tool_BeFlyMan_zsh flyman)
        {
           
            int flag = userBll.UserBeFlyMan_zsh(flyman);
            return flag;
        }

        //实例化短信接口类
        YunPianSmsClient client = new YunPianSmsClient();

        /// <summary>
        /// 发送短信的处理
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string sendmes(string mobile)
        {
            //接受手机号
            string tel = mobile;
            //发送短信，获取返回值
            var k = client.SendSms(tel);
            return k;
        }

        /// <summary>
        /// 验证输入的验证码是否正确
        /// </summary>
        /// <param name="CodeSee"></param>
        /// <returns></returns>
        [HttpGet]
        public int IsCode(string CodeSee)
        {
            //比较输入的验证码和后台保存的验证码是否正确，下面一步是获取后台保存的session验证码
            string SessionCode = client.SaveCode();
            if (CodeSee != SessionCode)
            {

                return 0;
            }
            else
            {
                return 1;
            }

        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Problems> P_Index()
        {
            return userBll.problems_index();
        }


        // GET: /problems_one/
        /// <summary>
        ///根据ID显示出不同的问题答案
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        [HttpGet]
        public Problems P_show(int ID)
        {
            return userBll.problems_show(ID);
        }


        /// <summary>
        /// 问题反馈
        /// </summary>
        /// <param name="back"></param>
        /// <param name="img"></param>
        /// <param name="pho"></param>
        /// <returns></returns>
        [HttpPost]
        public void message_ADD()
        {
            var a = HttpContext.Current.Request;
            string back = a["back"], pho = a["pho"], imgUrl = "";
            var root = "~/file/";
            var rootPath = HttpContext.Current.Server.MapPath(root);
            for (int i = 0; i < a.Files.Count; i++)
            {
                string newFileName = Guid.NewGuid() + a.Files[i].FileName;
                a.Files[i].SaveAs(System.IO.Path.Combine(rootPath, newFileName));
                if (i != 0)
                {
                    imgUrl += ",";
                }
                imgUrl += root + newFileName;
            }
            userBll.Opinions_ADD(back, imgUrl, pho);
            HttpContext.Current.Response.StatusCode = 200;
            HttpContext.Current.Response.Write("<script>alert('成功');location.href='" + a.UrlReferrer.ToString() + "'</script>");
            HttpContext.Current.Response.End();
        }


        /// <summary>
        /// 飞人个人中心
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public UserInfo GetUserShow()
        {
            UserInfo m = new UserInfo();
            m = mod();
            return m;
        }

        /// <summary>
        /// 关于我们
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<About> GetAboutsList()
        {

            return userBll.AboutUsList();
        }

        /// <summary>
        /// 个人中心--我的寄件订单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Mails> per_ji()
        {
           
            UserInfo m = new UserInfo();
            int id = 0;
           
            m = mod();
            if (m != null)
             id = m.userId;
            per_bll perbll = new per_bll();
            List<Mails> list = perbll.ji_list(id);
            return list;
        }

        /// <summary>
        /// 个人中心--我的收件订单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Temp> per_shou()
        {
            UserInfo m = new UserInfo();
            m = mod();
            int id = m.userId;
            per_bll perbll = new per_bll();
            List<Temp> list = perbll.shou_list(id);
            return list;
        }
    }
}
